package com.dllo.lanou.cookapp.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dllo.lanou.cookapp.R;
import com.dllo.lanou.cookapp.entity.AddCookEntity;
import com.dllo.lanou.cookapp.volly.GetVolleyImage;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by xijinhua on 2016/4/2.
 */
public class CookStepAdapter extends BaseAdapter{
    private List<AddCookEntity> addCookEntities ;
    private Context context;
    private LayoutInflater mInflater;

    private AddCookEntity   addCookEntity;

    public CookStepAdapter(Context context){
        this.context = context;
        mInflater = LayoutInflater.from(context);
    }

    public void addData(List<AddCookEntity> addCookEntity){

        this.addCookEntities = addCookEntity;
        Log.i("AddCookEntity", addCookEntities.size() + "");
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return addCookEntities !=null &&addCookEntities.size()>0 ?addCookEntities.size():0 ;
    }

    @Override
    public Object getItem(int position) {
        return addCookEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView =mInflater.inflate(R.layout.item_addstep,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();

        }

        AddCookEntity addCookEntity = addCookEntities.get(position);
        Log.i("AddCookEntity",addCookEntities.size()+"");
        holder.textView.setText(addCookEntity.getCount());
        String path = addCookEntities.get(position).getToYunImg();

        if (path!=null){
            if (path.contains("http://")){
                GetVolleyImage.getNetWorkImg(path, holder.imageView);
            }}
        String content = addCookEntities.get(position).getContent();
        if (content != null){
            holder.content.setText(content);
        }






        return convertView;
    }



    static class ViewHolder{

        @Bind(R.id.add_count)
        TextView textView ;
        @Bind(R.id.add_content)
        TextView content;
        @Bind(R.id.add_img)
        ImageView imageView;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


}

